package designpattern.command.llm.command;

import designpattern.command.llm.model.StringBuf;

public class AppendCommand implements Command {
    private final StringBuf stringBuf;
    private final String text;
    private int originalLength;

    public AppendCommand(StringBuf stringBuf, String text) {
        this.stringBuf = stringBuf;
        this.text = text;
    }

    @Override
    public void execute() {
        originalLength = stringBuf.length();
        stringBuf.append(text);
    }

    @Override
    public void undo() {
        stringBuf.delete(originalLength, text.length());
    }
}